package com.ChenYaRou.www.dao.impl;

import com.ChenYaRou.www.dao.CollectionDao;
import com.ChenYaRou.www.po.Collection;
import com.ChenYaRou.www.utils.GenerateSql;
import com.ChenYaRou.www.utils.JdbcUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @ClassName CollectionDaoImpl
 * @Description TODO
 * @Author 86183
 * @Date 2022/4/29 23:29
 * @Version 1.0
 **/
public class CollectionDaoImpl implements CollectionDao {
    /**
     * 新建收藏
     * @param collection 新收藏
     * @return 更新条数
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int insert(Collection collection) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().insert(collection));
    }

    /**
     * update collection state
     * @param collection collection需要更新的值
     * @param  oldCollection old collection
     * @return 成功与否
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int update(Collection collection, Collection oldCollection) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().update(collection,oldCollection));
    }

    /**
     * 删除收藏
     * @param  collection 删掉的收藏信息
     * @return 成功与否
     * @throws  SQLException
     */
    @Override
    public int delete(Collection collection) {
        return 0;
    }
    /**
     * 查找收藏集合
     * @param collection 条件collection
     * @return
     * @throws IllegalAccessException
     * @throws SQLException
     * @throws NoSuchFieldException
     * @throws InstantiationException
     */
    @Override
    public List<Collection> selectMore(Collection collection) throws IllegalAccessException, SQLException, NoSuchFieldException, InstantiationException {
        return JdbcUtil.getInstance().selectMore(GenerateSql.getInstance().select(collection), Collection.class);
    }
}
